require(['init'], function () {

  var tuid = location.search.urlToObj().tuid
  if(!localStorage.lang){
    localStorage.setItem('lang','zh');
  }
  if(localStorage.lang && localStorage.lang=='zh'){
    $('body').append('<script src="codebase/locale/locale_cn.js"  type="text/javascript" charset="utf-8"></script>');
    $('body').append('<script src="codebase/locale/recurring/locale_recurring_cn.js" charset="utf-8"></script>');
  }
  else {
    $('body').append('<script src="codebase/locale/locale_en.js"  type="text/javascript" charset="utf-8"></script>');
    $('body').append('<script src="codebase/locale/recurring/locale_recurring_en.js" charset="utf-8"></script>');
  }
  function loadTeacherData(teacheruid, callback) {
    ajaxMethod({
      url: '/api/teacher/' + teacheruid,
      success: function (data) {
        $('#J_name').text(data.lastname);
        $('#J_phone').text(data.mobile);
        $('[name=tuid]').val(data.teacheruid);
        $('#J_remark1').text(data.remark1 || '');
        $('#J_remark2').text(data.remark2 || '');

        (typeof callback == 'function') && callback()
      }
    })
  }

  var create_lightbox = [
    /*{
      name: "描述",
      height: 30,
      map_to: "text",
      type: "textarea",
      default_value: ''
    },*/
    {
      name:"recurring",
      type:"recurring",
      map_to:"rec_type",
      button:"recurring",
      // form:"my_recurring_form"
    },
    {
      name: "time",
      height: 72,
      type: "time",
      map_to: "auto"
    }
  ];

  schedulerInit({
    tuid: tuid,
    url: '/api/teacherworktime',
    checkUrl: '/api/schedules/check',
    create_lightbox: create_lightbox,
    edit_lightbox: [
      {
        name: "time",
        height: 72,
        type: "time",
        map_to: "auto"
      }
    ],
    onCreate: true,
    schedulerType: 1,
    processData: function(data, courseList) {
      var dataArr = []
      $.each(data, function (i, v) {
        dataArr.push({
          start_date: new Date(v.begintime),
          end_date: new Date(v.endtime),
          timeuid: v.timeuid,
          edit: true,
          color: '#96d6e3'
        })
      })
      /*$.each(data, function (i,v) {
        v.timespecs[0] || (v.timespecs[0] = {})
        var studentArr = v.students || [];
        var studentNameArr = [];
        $.each(studentArr, function () {
          studentNameArr.push(this.name);
        })

        var cur = {
          start_date: new Date(v.begintime.replace('T',' ')),
          end_date: new Date(v.endtime.replace('T',' ')),
          timeuid: v.timeuid,
          text: v.timespecs[0].coursetypename,

          quotas: v.timespecs[0].quotas || '0',
          usequotas: v.timespecs[0].usequotas || '0',
          coursetype: v.timespecs[0].coursetypeid || '0',
          students: studentNameArr.join(', ') || '空',
          color: getCourseColorById(courseList, v.timespecs[0].coursetypeid) || '#96d6e3',
          edit: true,
          lessonname: v.timespecs[0].remark || ''
        }

        if(cur.quotas != '0' && cur.quotas === cur.usequotas) {
          cur.color = 'red';
        }
        dataArr.push(cur)
      })*/
      return dataArr;
    }
    // bgColor: 'rgba(23, 150, 176, 0.3)'
  })
  loadTeacherData(tuid)

})
